package main

import (
	"Info/colly"
	"Info/config"
	"Info/dao/mysql"
	"Info/logger"
	"fmt"
	"github.com/robfig/cron"
	"go.uber.org/zap"
	"log"
)

func main() {

	// 1、加载配置
	if err := config.Init(); err != nil {
		fmt.Printf("init config error : %s \n", err)
		return
	}
	// 2、初始化日志
	if err := logger.Init(config.Conf.LogConfig, config.Conf.Mode); err != nil {
		fmt.Printf("init logger error : %s \n", err)
		return
	}
	defer zap.L().Sync()
	// 3、初始化MySQL
	if err := mysql.Init(config.Conf.MySQLConfig); err != nil {
		fmt.Printf("init mysql error : %s \n", err)
		return
	}
	defer mysql.Close()

	i := 0
	c := cron.New()
	spec := "0 1 * * *"
	//spec := "0/5 * * * *"
	c.AddFunc(spec, func() {
		i++
		colly.CollyData()
		log.Println("Perform crawler task", i)
	})
	c.Start()
	//阻塞
	select {}
}
